#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"
void init_stack(ST* s1)
{
	assert(s1);
	s1->stack = NULL;
	s1->capacity = 0;
	s1->top = 0;
}
void push_stack(ST* s1,STDateType x)
{
	assert(s1);
	if (s1->top == s1->capacity)
	{
		int newcapacity = (s1->capacity==0)?4:(s1->capacity)*2;
		s1->stack = (STDateType*)realloc(s1->stack, sizeof(STDateType)*newcapacity);
		if (s1->stack == NULL)
		{
			perror("push_stack");
			exit(-1);
		}
		s1->capacity = newcapacity;
	}
	s1->stack[s1->top] = x;
	s1->top++;
}
void pop_stack(ST* s1)
{
	assert(s1);
	assert(s1->top);
	s1->top--;
}
int stack_size(ST* s1)
{
	assert(s1);
	return s1->top;
}
int if_empty(ST* s1)
{
	assert(s1);
	return s1->top == 0;
}
void destory_stack(ST* s1)
{
	assert(s1);
	s1->capacity = 0;
	s1->top = 0;
	free(s1->stack);
}
STDateType stack_top(ST*s1)
{
	assert(s1);
	assert(s1->top);
	return s1->stack[s1->top - 1];
}